Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
filter-obj
Advanced tools
The filter-obj npm package allows users to filter the properties of an object based on specific criteria. This can be useful for creating subsets of an object, removing unwanted properties, or selectively copying properties based on dynamic conditions.
Filtering based on property names
This feature allows you to filter an object by specifying which property names to keep. It is useful for extracting specific properties from an object.
const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, ['a', 'c']);
console.log(filtered); // Output: { a: 1, c: 3 }
Filtering using a function
This feature enables filtering based on a function that takes key and value as arguments. It allows for more dynamic and condition-based filtering, such as filtering out properties based on their types or values.
const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, (key, value) => typeof value === 'number');
console.log(filtered); // Output: { a: 1, c: 3 }
lodash.pick is a method from the Lodash library that creates an object composed of the picked object properties. It is similar to filter-obj but is part of a larger utility library, which might be preferable for users who need other utility functions.
object-filter is another npm package that provides similar functionality to filter-obj, allowing filtering of object properties based on a predicate function. It compares to filter-obj in terms of functionality but might have different implementation details or additional options.
Filter object keys and values into a new object
npm install filter-obj
import {includeKeys, excludeKeys} from 'filter-obj';
const object = {
foo: true,
bar: false
};
const newObject = includeKeys(object, (key, value) => value === true);
//=> {foo: true}
const newObject2 = includeKeys(object, ['bar']);
//=> {bar: false}
const newObject = excludeKeys(object, (key, value) => value === true);
//=> {bar: false}
const newObject3 = excludeKeys(object, ['bar']);
//=> {foo: true}
Type: object
The source object to filter properties from.
Type: (sourceKey: string | symbol, sourceValue: unknown, source: object) => boolean
A predicate function that determines whether a property should be filtered.
Type: Array<string | symbol>
An array of property keys to be filtered.
FAQs
Filter object keys and values into a new object
The npm package filter-obj receives a total of 5,180,934 weekly downloads. As such, filter-obj popularity was classified as popular.
We found that filter-obj demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.